/********************************************************************************
* File Name:	databaseconnection.cpp
* Description:	第7章实例训练
* Reference book:《Linux环境下Qt4图形界面与MySQL编程》，机械工业出版社.2012.1
* E_mail: openlinux2011@gmail.com
*
********************************************************************************/
#include "databaseconnection.h"
#include <QSqlQuery>

databaseconnection::databaseconnection()
{
}

QSqlDatabase databaseconnection::db = QSqlDatabase::addDatabase("QMYSQL");
bool databaseconnection::Open()
{
    db.setHostName(QLatin1String("localhost"));
    db.setUserName("root");
    db.setPassword("1");
    db.setDatabaseName("house");
    if(!db.open())
    {
        return false;
    }

    //db.exec("SET NAMES 'gbk'");

    return true;
}
void databaseconnection::Close()
{
    db.close();
}
